package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RevenueDonations;
import com.ruoyi.system.service.IRevenueDonationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户收益Controller
 * 
 * @author shawu
 * @date 2024-08-16
 */
@RestController
@RequestMapping("/system/donations")
public class RevenueDonationsController extends BaseController
{
    @Autowired
    private IRevenueDonationsService revenueDonationsService;

    /**
     * 查询用户收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:donations:list')")
    @GetMapping("/list")
    public TableDataInfo list(RevenueDonations revenueDonations)
    {
        startPage();
        List<RevenueDonations> list = revenueDonationsService.selectRevenueDonationsList(revenueDonations);
        return getDataTable(list);
    }

    /**
     * 导出用户收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:donations:export')")
    @Log(title = "用户收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RevenueDonations revenueDonations)
    {
        List<RevenueDonations> list = revenueDonationsService.selectRevenueDonationsList(revenueDonations);
        ExcelUtil<RevenueDonations> util = new ExcelUtil<RevenueDonations>(RevenueDonations.class);
        util.exportExcel(response, list, "用户收益数据");
    }

    /**
     * 获取用户收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:donations:query')")
    @GetMapping(value = "/{revenueId}")
    public AjaxResult getInfo(@PathVariable("revenueId") Long revenueId)
    {
        return success(revenueDonationsService.selectRevenueDonationsByRevenueId(revenueId));
    }

    /**
     * 新增用户收益
     */
    @PreAuthorize("@ss.hasPermi('system:donations:add')")
    @Log(title = "用户收益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RevenueDonations revenueDonations)
    {
        return toAjax(revenueDonationsService.insertRevenueDonations(revenueDonations));
    }

    /**
     * 修改用户收益
     */
    @PreAuthorize("@ss.hasPermi('system:donations:edit')")
    @Log(title = "用户收益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RevenueDonations revenueDonations)
    {
        return toAjax(revenueDonationsService.updateRevenueDonations(revenueDonations));
    }

    /**
     * 删除用户收益
     */
    @PreAuthorize("@ss.hasPermi('system:donations:remove')")
    @Log(title = "用户收益", businessType = BusinessType.DELETE)
	@DeleteMapping("/{revenueIds}")
    public AjaxResult remove(@PathVariable Long[] revenueIds)
    {
        return toAjax(revenueDonationsService.deleteRevenueDonationsByRevenueIds(revenueIds));
    }
}
